Hệ thống quản lý ISP trong PHP

1 <?php
2
3     
// Start from getting the hader which contains some settings we need
4     require_once
'includes/headx.php';
5     
// require the admins class which containes most functions applied to admins
6     require_once
"includes/classes/admin-class.php";
7
8     $admins =
new Admins($dbh);
9
10     $page = isset($_GET[
'p' ])?$_GET[ 'p' ]:'';
11
12     
if($page == 'add'){
13             $name = htmlentities($_POST[
'name']);
14             $unit = htmlentities($_POST[
'unit']);
15             $details = htmlentities($_POST[
'details']);
16             $category = htmlentities($_POST[
'category']);
17             
if (!$admins->addNewProduct($name, $unit, $details, $category))
18             {
19                 echo
"Sorry Data could not be inserted !";
20             }
else {
21                 echo
"Well! You've successfully inserted new data!";
22             }
23     }
else if($page == 'del'){
24         $id = $_POST[
'id'];
25         
if (!$admins->deleteProduct($id))
26         {
27             echo
"Sorry Data could not be deleted !";
28         }
else {
29             echo
"Well! You've successfully deleted a product!";
30         }
31
32     }
else if($page == 'edit'){
33         $name = htmlentities($_POST[
'name']);
34         $unit = htmlentities($_POST[
'unit']);
35         $details = htmlentities($_POST[
'details']);
36         $category = htmlentities($_POST[
'category']);
37         $id = $_POST[
'id'];
38         
if (!$admins->updateProduct($id, $name, $unit, $details, $category))
39         {
40             echo
"Sorry Data could not be inserted !";
41         }
else {
42
43             $commons->redirectTo(SITE_PATH.
'products.php');
44         }
45
46     }
else{
47         $products = $admins->fetchProducts();
48         
if (isset($products) && sizeof($products) > 0){
49             
foreach ($products as $product) { ?>
50     <tr>
51         <td
class="search" scope="row">
52             <?=$product->pro_id?>
53         </td>
54         <td>
55             <button type=
"button" class="btn btn-success btn-sm" id="edit" data-toggle="modal" data-target="#edit-<?=$product->pro_id?>">EDIT</button>
56             <!-- Update modal -->
57             <div
class="fade modal" id="edit-<?=$product->pro_id?>">
58                 <div
class="modal-dialog" role="document">
59                     <div
class="modal-content">
60                         <div
class="modal-header">
61                             <button type=
"button" class="close" data-dismiss="modal">×</button>
62                             <h4>Edit Details</h4>
63                         </div>
64                         <form method=
"POST" action="product_approve.php?p=edit">
65                             <div
class="modal-body">
66                                 <!-- The
async form to send and replace the modals content with its response -->
67                                 <!-- form content -->
68                                 <input type=
"hidden" name="id" id="<?=$product->pro_id?>" value="<?=$product->pro_id?>">
69                                 <div
class="form-group has-success">
70                                     <label
for="name">Name</label>
71                                     <input type=
"text" class="form-control" id="nm-<?=$product->pro_id?>" name="name" value="<?=$product->pro_name?>" required>
72                                 </div>
73                                 <div
class="form-group">
74                                     <label
for="unit">Unit</label>
75                                     <input type=
"text" class="form-control" id="un-<?=$product->pro_id?>" name="unit" value="<?=$product->pro_unit?>" required>
76                                 </div>
77                                 <div
class="form-group">
78                                     <label
for="details">Details</label>
79                                     <input type=
"text" class="form-control" id="dt-<?=$product->pro_id?>" name="details" value="<?=$product->pro_details?>" required>
80                                 </div>
81                                 <div
class="form-group">
82                                     <label
for="category">Select Category</label>
83                                     <
select class="form-control form-control-sm" name="category" id="category">
84                                                 <option><?=$product->pro_category?></option>
85                                                 <?php
86                                                 $categories = $admins->fetchCategory();
87                                                     
if (isset($categories) && sizeof($categories) > 0){
88                                                     
foreach ($categories as $category) { ?>
89                                                     <option
value='<?=$category->cat_name?>'><?=$category->cat_name?></option>
90                                                 <?php }} ?>
91                                               </
select>
92                                 </div>
93                             </div>
94                             <div
class="modal-footer">
95                                 <button type=
"submit" onclick="upData(<?=$product->pro_id?>)" class="btn btn-primary">Update</button>
96                                 <a href=
"#" class="btn btn-warning" data-dismiss="modal">Cancel</a>
97                             </div>
98                         </form>
99                     </div>
100                 </div>
101             </div>
102             <!-- modalend -->
103             <button type=
"button" id="delete" onclick="delData(<?=$product->pro_id?>)" class="btn btn-warning btn-sm">DELETE</button>
104         </td>
105         <td
class="search">
106             <?=$product->pro_name?>
107         </td>
108         <td>
109             <?=$product->pro_unit?>
110         </td>
111         <td
class="search">
112             <?=$product->pro_details?>
113         </td>
114         <td
class="search">
115             <?=$product->pro_category?>
116         </td>
117     </tr>
118     <?php
119             }
120         }
121     }
122 ?>


Gõ tìm kiếm nhanh...